{[{define "admin/role/auth.html"}]}
<style>
    .layui-iconpicker-body.layui-iconpicker-body-page .hide {
        display: none;
    }
</style>
<link rel="stylesheet" href="/static/admin/css/public.css" media="all">
<link rel="stylesheet" href="/static/plugs/layui-v2.5.6/css/layui.css" media="all">



<div class="layuimini-container">
    <form id="app-form" class="layui-form layuimini-form">

        <input type="hidden" name="rid" value="{[{.rid}]}">

        <div class="layui-form-item">
            <label class="layui-form-label required">角色</label>
            <div class="layui-input-block">
                <input type="text" name="name" class="layui-input" lay-verify="required" readonly lay-reqtext="请输入用户昵称" placeholder="请输入用户昵称" value="{[{.item.Name}]}">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label required">分配权限</label>
            <div class="layui-input-block">
                <div id="node_ids" class="demo-tree-more"></div>
            </div>
        </div>

        <div class="hr-line"></div>
        <div class="layui-form-item text-center">
            <button type="submit" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit lay-filter="add">确认</button>
            <button type="reset" class="layui-btn layui-btn-primary layui-btn-sm">重置</button>
        </div>

    </form>
</div>
<script src="/static/layuimini/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="/static/layuimini/js/lay-config.js" charset="utf-8"></script>
<script>

    layui.use(['form', 'jquery','tree','sh'], function () {
        var $ = layui.jquery,
            form = layui.form,
            tree = layui.tree,
            layer = layui.layer,
            sh = layui.sh;

            var ids = [];

           index =  function (checkedData){
                $.each(checkedData, function (i, v) {
                    ids.push(v.id);
                    if (v.children !== undefined && v.children.length > 0) {
                        index(v.children)
                    }
                });
            }

           sh.request.get(
                {
                    url: '/admin/role/auth?rid={[{.rid}]}',
                }, function (res) {
                    tree.render({
                        elem: '#node_ids',
                        checkChirld: false,
                        data: res.data,
                        showCheckbox: true,
                        id: 'nodeDataId',

                    });
                }
           );

        form.on('submit(add)', function (data) {
            data = data.field;

            var checkedData = tree.getChecked('nodeDataId',true);
            index(checkedData);

            data.ids = ids;

            sh.request.post(
                {
                    url: '/admin/role/auth_ajax',
                    data: data,
                }, function (res) {
                    sh.msg.success('添加成功', function () {
                        window.parent.location.reload();//刷新父页面
                        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                        parent.layer.close(index);
                    });
                }
            );
            return false;
        });
    });



</script>
{[{end}]}


